<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var arrayPairSum = function(nums) {
        nums.sort(function(a,b){
            return a-b;
        })
        const len = nums.length;
        let sum = 0;
        for(let i=0; i<len; i=i+2){
            sum+=nums[i];
        }
        return sum;
    };
    let arr = [1,4,3,2];
    console.log(arrayPairSum(arr));
    
</script>
</html>